package org.example;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @description: RabbitMQ 的连接工具类
 * @author: WangBlue
 * @create: 2023-11-25 18:45
 **/
public class RabbitMQUtils {
    public static Channel getChannel() throws IOException, TimeoutException {
        // 创建一个工厂
        ConnectionFactory factory = new ConnectionFactory();

        //工厂IP 连接RabbitMQ对列
        factory.setHost("localhost");
        //用户名
        factory.setUsername("admin");
        //密码
        factory.setPassword("admin");
        factory.setVirtualHost("/demo");

        //创建连接
        Connection connection = factory.newConnection();
        //获取信道
        Channel channel = connection.createChannel();

        return channel;
    }
}
